package com.cby.widget.sample.bubblenavigation

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.cby.widget.sample.R
import com.cby.widget.sample.databinding.ActivityBubbleNavTopBarBinding
import com.cby.widget.sample.ext.binding
import com.cby.widget.sample.fragments.ScreenSlidePageFragment

/**
 * @description: BubbleNavTopBarActivity
 *
 * @author ChenBaoyang
 * @date 2021/10/16 15:43
 */
class BubbleNavTopBarActivity : AppCompatActivity() {

    private val binding: ActivityBubbleNavTopBarBinding by binding()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_bubble_nav_top_bar)

        val fragList = ArrayList<ScreenSlidePageFragment>()
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.restaurant), R.color.orange_inactive))
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.room), R.color.red_inactive))
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.happy), R.color.green_inactive))
        val pagerAdapter = ScreenSlidePagerAdapter(fragList, supportFragmentManager)
        binding.viewPager.adapter = pagerAdapter
        binding.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(p0: Int) {

            }

            override fun onPageScrolled(p0: Int, p1: Float, p2: Int) {

            }

            override fun onPageSelected(p0: Int) {
                binding.topNavigationConstraint.setCurrentActiveItem(p0)
            }

        })

        binding.topNavigationConstraint.setNavigationChangeListener { _, position ->
            binding.viewPager.setCurrentItem(position, true)
        }
    }

}